<%-- 
    Document   : login
    Created on : 2019-9-2, 10:43:27
    Author     : danny
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    
Cookie ckUserName = null, ckPassword = null;
Cookie[] cookies = request.getCookies();
if (cookies != null)
    for (Cookie cookie : cookies) {
        if (cookie.getName().equals("userName")) {
            ckUserName = cookie;
        } else if (cookie.getName().equals("password")) {
            ckPassword = cookie;
        }
    }

if (ckUserName != null && ckPassword != null) {
    String userName = ckUserName.getValue();
    String pwd = ckPassword.getValue();
    if ("admin".equals(userName) && "123456".equals(pwd)) {
        response.sendRedirect(request.getContextPath()+"/index.jsp");
    }
}

%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>登录表单</h1>
        <form action="<%=request.getContextPath() %>/login.do" method="post">
            用户名：<input name="userName" type="text"/><br/>
            密码：<input name="pwd" type="password"/><br/>
            <span style="color: red">${error}</span><br/>
            <input type="submit" value="登录"/>
        </form>
    </body>
</html>
